<?php

class OtrorubroController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column2';
	private $_productoService;
	
	public function init()
	{
		$this->_productoService = new productoService();
			
		parent::init();
	}

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete', // we only allow deletion via POST request
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','delete','getRubros'),
				'users'=>array('*'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	public function actionGetRubros(){
		$rubros = $this->_productoService->getRubros($_POST['id']);
		$no_rubros = $this->_productoService->getNoRubros($_POST['id']);
		$this->renderPartial('tablas',array('incluidos'=>$rubros,'no_incluidos'=>$no_rubros));
	}
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		if (isset($_POST['idproducto']) && isset($_POST['idrubro']))
		{
			$this->_productoService->asociarRubro($_POST['idproducto'], $_POST['idrubro']);
			
		}
		return;
	}


	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete()
	{
		if (isset($_POST['idproducto']) && isset($_POST['idrubro']))
		{
			$this->_productoService->eliminarRubro($_POST['idproducto'], $_POST['idrubro']);
			
		}
		return;
	}

}
